package com.pan.yu.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pan.yu.entity.Student;
import com.pan.yu.entity.Teacher;
import com.pan.yu.mapper.StudentNeoMapper;
import com.pan.yu.mapper.TeacherNeoMapper;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
	
	@Autowired
	private TeacherNeoMapper teacherNeoMapper;
	@Autowired
	private StudentNeoMapper studentNeoMapper;
	
	@GetMapping("/create/{name}/{age}/{subject}")
	public void createNode(@PathVariable("name")String name,@PathVariable("age")Integer age,
			@PathVariable("subject")String subject){
		Teacher teacher = new Teacher();
		teacher.setAge(age);
		teacher.setName(name);
		teacher.setSubject(subject);
		teacherNeoMapper.save(teacher);
	}
	
	@GetMapping("/relation/{parent}/{child}")
	public void createNode(@PathVariable("parent")Long parent,@PathVariable("child")Long child){
		
		teacherNeoMapper.createRelationOut(parent,"学生",child);
	}
	
	
	@GetMapping("/find/{parent}/{child}")
	public void createNode(@PathVariable("parent")Long parent){
		
		Optional<Teacher> findById = teacherNeoMapper.findById(parent);
		System.out.println(findById.get());
		
		
		List<Teacher> findAll1 = teacherNeoMapper.findAll(1l,"1",1l);
		System.out.println(findAll1);
	}
}
